package com.warom.sdg.config;

import com.warom.sdg.enums.ModuleType;
import com.warom.sdg.model.DeviceType;
import com.warom.sdg.model.PlcDataEntity;
import com.warom.sdg.util.ModbusHelper;
import com.warom.sdg.config.MeasurementPoint;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * PLC测点配置管理类
 * 用于统一管理各模块所需的PLC设备测点信息
 */
public class PlcMeasurementConfig {

        // 粮情检测测点列表 - 新增
        public static final List<MeasurementPoint> grainSituationPoints = new ArrayList<>();

        // 模块-设备-测点的映射关系
        public static final Map<ModuleType, Map<DeviceType, List<MeasurementPoint>>> moduleDevicePointsMap = new HashMap<>();

        // 英文名称到测点的映射，用于快速查找测点（确保唯一性）
        public static final Map<String, MeasurementPoint> englishNamePointMap = new HashMap<>();

        // 静态初始化配置
        static {
                initPlcMeasurementConfig();
                // 在所有数据初始化完成后执行测点映射初始化
                initPointMaps();
        }

        /**
         * 初始化PLC测点配置
         */
        private static void initPlcMeasurementConfig() {
                // 初始化气体检测模块配置 - 只从西门子PLC获取
                Map<DeviceType, List<MeasurementPoint>> gasMonitoringMap = new HashMap<>();

                // 西门子PLC的气体检测测点
                List<MeasurementPoint> siemensGasPoints = new ArrayList<>();
                siemensGasPoints.add(new MeasurementPoint("磷化氢", "PH3", "40017", "PPM",
                                "磷化氢浓度", 0, 100, 5, 10, 10.0f, MeasurementPoint.PointType.VALUE));
                siemensGasPoints.add(new MeasurementPoint("氧气", "O2", "40004", "%",
                                "氧气浓度", 0, 25, 19, 18, 1.0f, MeasurementPoint.PointType.VALUE));
                siemensGasPoints.add(new MeasurementPoint("二氧化碳", "CO2", "40013", "PPM",
                                "二氧化碳浓度", 0, 5, 0.5, 1.0, 10.0f, MeasurementPoint.PointType.VALUE));
                gasMonitoringMap.put(DeviceType.SIEMENS_S7, siemensGasPoints);
                // 将气体检测模块添加到总映射中
                moduleDevicePointsMap.put(ModuleType.GAS_MONITORING, gasMonitoringMap);

                // 初始化通风控制模块配置 - 只从西门子PLC获取
                List<MeasurementPoint> siemensVentilationPoints = new ArrayList<>();

                // 添加环流风机测点
                MeasurementPoint fan1 = new MeasurementPoint("1#环流风机",
                                "Circulation_Fan_1", "40057", "",
                                "1号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan1);

                MeasurementPoint fan2 = new MeasurementPoint("2#环流风机",
                                "Circulation_Fan_2", "40058", "",
                                "2号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan2);

                MeasurementPoint fan3 = new MeasurementPoint("3#环流风机",
                                "Circulation_Fan_3", "40059", "",
                                "3号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan3);

                MeasurementPoint fan4 = new MeasurementPoint("4#环流风机",
                                "Circulation_Fan_4", "40060", "",
                                "4号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan4);

                MeasurementPoint fan5 = new MeasurementPoint("5#环流风机",
                                "Circulation_Fan_5", "40061", "",
                                "5号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan5);

                MeasurementPoint fan6 = new MeasurementPoint("6#环流风机",
                                "Circulation_Fan_6", "40062", "",
                                "6号环流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan6);

                // 属性测点 - 环流风机状态测点（不用于页面展示）
                // 1#环流风机状态测点
                MeasurementPoint fan1RunStatus = new MeasurementPoint("1#环流风机运行状态",
                                "Circulation_Fan_1_Run_Status", "10017", "",
                                "1号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan1RunStatus);

                MeasurementPoint fan1Fault = new MeasurementPoint("1#环流风机故障报警",
                                "Circulation_Fan_1_Fault", "10018", "",
                                "1号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan1Fault);

                // 将属性测点添加到主测点
                fan1.addAttributePoint(fan1RunStatus);
                fan1.addAttributePoint(fan1Fault);

                // 2#环流风机状态测点
                MeasurementPoint fan2RunStatus = new MeasurementPoint("2#环流风机运行状态",
                                "Circulation_Fan_2_Run_Status", "10019", "",
                                "2号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan2RunStatus);

                MeasurementPoint fan2Fault = new MeasurementPoint("2#环流风机故障报警",
                                "Circulation_Fan_2_Fault", "10020", "",
                                "2号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan2Fault);

                // 将属性测点添加到主测点
                fan2.addAttributePoint(fan2RunStatus);
                fan2.addAttributePoint(fan2Fault);

                // 3#环流风机状态测点
                MeasurementPoint fan3RunStatus = new MeasurementPoint("3#环流风机运行状态",
                                "Circulation_Fan_3_Run_Status", "10021", "",
                                "3号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan3RunStatus);

                MeasurementPoint fan3Fault = new MeasurementPoint("3#环流风机故障报警",
                                "Circulation_Fan_3_Fault", "10022", "",
                                "3号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan3Fault);

                // 将属性测点添加到主测点
                fan3.addAttributePoint(fan3RunStatus);
                fan3.addAttributePoint(fan3Fault);

                // 4#环流风机状态测点
                MeasurementPoint fan4RunStatus = new MeasurementPoint("4#环流风机运行状态",
                                "Circulation_Fan_4_Run_Status", "10023", "",
                                "4号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan4RunStatus);

                MeasurementPoint fan4Fault = new MeasurementPoint("4#环流风机故障报警",
                                "Circulation_Fan_4_Fault", "10024", "",
                                "4号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan4Fault);

                // 将属性测点添加到主测点
                fan4.addAttributePoint(fan4RunStatus);
                fan4.addAttributePoint(fan4Fault);

                // 5#环流风机状态测点
                MeasurementPoint fan5RunStatus = new MeasurementPoint("5#环流风机运行状态",
                                "Circulation_Fan_5_Run_Status", "10025", "",
                                "5号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan5RunStatus);

                MeasurementPoint fan5Fault = new MeasurementPoint("5#环流风机故障报警",
                                "Circulation_Fan_5_Fault", "10026", "",
                                "5号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan5Fault);

                // 将属性测点添加到主测点
                fan5.addAttributePoint(fan5RunStatus);
                fan5.addAttributePoint(fan5Fault);

                // 6#环流风机状态测点
                MeasurementPoint fan6RunStatus = new MeasurementPoint("6#环流风机运行状态",
                                "Circulation_Fan_6_Run_Status", "10027", "",
                                "6号环流风机运行状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan6RunStatus);

                MeasurementPoint fan6Fault = new MeasurementPoint("6#环流风机故障报警",
                                "Circulation_Fan_6_Fault", "10028", "",
                                "6号环流风机故障报警", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM,
                                MeasurementPoint.DeviceSubType.CIRCULATION_FAN, 0.0);
                siemensVentilationPoints.add(fan6Fault);

                // 将属性测点添加到主测点
                fan6.addAttributePoint(fan6RunStatus);
                fan6.addAttributePoint(fan6Fault);

                // 将通风测点添加到设备映射中
                Map<DeviceType, List<MeasurementPoint>> ventilationMap = new HashMap<>();
                ventilationMap.put(DeviceType.SIEMENS_S7, siemensVentilationPoints);
                moduleDevicePointsMap.put(ModuleType.VENTILATION, ventilationMap);

                // 添加轴流风机配置
                List<MeasurementPoint> siemensAxialFanPoints = new ArrayList<>();
                siemensAxialFanPoints.add(new MeasurementPoint("1#轴流风机",
                                "Axial_Fan_1", "40051", "",
                                "1号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));
                siemensAxialFanPoints.add(new MeasurementPoint("2#轴流风机",
                                "Axial_Fan_2", "40052", "",
                                "2号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));
                siemensAxialFanPoints.add(new MeasurementPoint("3#轴流风机",
                                "Axial_Fan_3", "40053", "",
                                "3号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));
                siemensAxialFanPoints.add(new MeasurementPoint("4#轴流风机",
                                "Axial_Fan_4", "40054", "",
                                "4号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));
                siemensAxialFanPoints.add(new MeasurementPoint("5#轴流风机",
                                "Axial_Fan_5", "40055", "",
                                "5号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));
                siemensAxialFanPoints.add(new MeasurementPoint("6#轴流风机",
                                "Axial_Fan_6", "40056", "",
                                "6号轴流风机状态", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS,
                                MeasurementPoint.DeviceSubType.AXIAL_FAN, 0.0));

                // 将轴流风机配置添加到西门子测点列表中
                siemensVentilationPoints.addAll(siemensAxialFanPoints);

                // 添加自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#1", "Natural_Window_1",
                                "40101", "40151", "40102", "40152",
                                "1#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加2号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#2", "Natural_Window_2",
                                "40103", "40153", "40104", "40154",
                                "2#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加3号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#3", "Natural_Window_3",
                                "40105", "40155", "40106", "40156",
                                "3#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加4号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#4", "Natural_Window_4",
                                "40107", "40157", "40108", "40158",
                                "4#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加5号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#5", "Natural_Window_5",
                                "40109", "40159", "40110", "40160",
                                "5#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加6号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#6", "Natural_Window_6",
                                "40111", "40161", "40112", "40162",
                                "6#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加7号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#7", "Natural_Window_7",
                                "40113", "40163", "40114", "40164",
                                "7#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加8号自然通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "自然通风窗#8", "Natural_Window_8",
                                "40115", "40165", "40116", "40166",
                                "8#自然通风窗", MeasurementPoint.DeviceSubType.NATURAL_WINDOW));

                // 添加轴流通风窗
                // 添加1号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#1", "Axial_Window_1",
                                "40201", "40251", "40202", "40252",
                                "1#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加2号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#2", "Axial_Window_2",
                                "40203", "40253", "40204", "40254",
                                "2#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加3号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#3", "Axial_Window_3",
                                "40205", "40255", "40206", "40256",
                                "3#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加4号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#4", "Axial_Window_4",
                                "40207", "40257", "40208", "40258",
                                "4#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加5号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#5", "Axial_Window_5",
                                "40209", "40259", "40210", "40260",
                                "5#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加6号轴流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "轴流通风窗#6", "Axial_Window_6",
                                "40211", "40261", "40212", "40262",
                                "6#轴流通风窗", MeasurementPoint.DeviceSubType.AXIAL_WINDOW));

                // 添加环流通风窗
                // 添加1号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#1", "Circulation_Window_1",
                                "40301", "40351", "40302", "40352",
                                "1#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 添加2号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#2", "Circulation_Window_2",
                                "40303", "40353", "40304", "40354",
                                "2#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 添加3号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#3", "Circulation_Window_3",
                                "40305", "40355", "40306", "40356",
                                "3#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 添加4号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#4", "Circulation_Window_4",
                                "40307", "40357", "40308", "40358",
                                "4#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 添加5号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#5", "Circulation_Window_5",
                                "40309", "40359", "40310", "40360",
                                "5#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 添加6号环流通风窗
                siemensVentilationPoints.add(MeasurementPoint.createWindow(
                                "环流通风窗#6", "Circulation_Window_6",
                                "40311", "40361", "40312", "40362",
                                "6#环流通风窗", MeasurementPoint.DeviceSubType.CIRCULATION_WINDOW));

                // 更新通风控制模块映射
                ventilationMap.put(DeviceType.SIEMENS_S7, siemensVentilationPoints);
                moduleDevicePointsMap.put(ModuleType.VENTILATION, ventilationMap);

                // 初始化气体检测模块配置 - 只从西门子PLC获取
                Map<DeviceType, List<MeasurementPoint>> otherMap = new HashMap<>();
                // 创建其他设备测点列表
                List<MeasurementPoint> siemensOtherMap = new ArrayList<>();

                // 添加照明回路测点
                siemensOtherMap.add(new MeasurementPoint("1#照明回路", "Lighting_Circuit_1", "40064", "",
                                "1#照明回路状态 VW126 V127.0 Q1.5", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS));

                siemensOtherMap.add(new MeasurementPoint("2#照明回路", "Lighting_Circuit_2", "40065", "",
                                "2#照明回路状态 VW128 V129.0 Q1.6", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS));

                // 添加移动风机插座测点
                MeasurementPoint mobileFanSocket = new MeasurementPoint("移动风机插座", "Mobile_Fan_Socket", "40063", "",
                                "移动风机插座 VW124 V125.0 控制用", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.STATUS);
                siemensOtherMap.add(mobileFanSocket);

                // 添加移动风机运行状态和故障报警属性测点
                MeasurementPoint mobileFanRunStatus = new MeasurementPoint("移动风机运行状态", "Mobile_Fan_Run_Status", "10029",
                                "",
                                "移动风机运行状态 I3.4 0:关闭 1:开启", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.RUN_STATUS);
                siemensOtherMap.add(mobileFanRunStatus);

                MeasurementPoint mobileFanFault = new MeasurementPoint("移动风机故障报警", "Mobile_Fan_Fault", "10030", "",
                                "移动风机故障报警 I3.5 0:关闭 1:开启", 0, 1, 0, 0, 1.0f, MeasurementPoint.PointType.FAULT_ALARM);
                siemensOtherMap.add(mobileFanFault);

                // 将属性测点添加到主测点
                mobileFanSocket.addAttributePoint(mobileFanRunStatus);
                mobileFanSocket.addAttributePoint(mobileFanFault);

                // 创建其他设备模块映射
                Map<DeviceType, List<MeasurementPoint>> yrOtherMap = new HashMap<>();
                otherMap.put(DeviceType.SIEMENS_S7, siemensOtherMap);
                // 将其他设备模块添加到总映射中
                // moduleDevicePointsMap.put(ModuleType.OTHER, otherMap);

                // 添加智能称重仪表测点到OMRON_CP_4设备类型
                List<MeasurementPoint> omronCP4Points = new ArrayList<>();
                omronCP4Points.add(new MeasurementPoint("智能称重仪表", "Warehouse_Pressure", "40001", "KG",
                                "智能称重仪表值", 0, 2000, 1500, 1800, 10f, MeasurementPoint.PointType.VALUE));
                otherMap.put(DeviceType.OMRON_CP_4, omronCP4Points);

                moduleDevicePointsMap.put(ModuleType.OTHER, otherMap);

                initYouRenPointList();

                // 配置测点更新频率
                configureUpdateFrequencies();
        }

        /**
         * 配置不同类型测点的更新频率
         */
        private static void configureUpdateFrequencies() {
                // 遍历所有模块
                for (ModuleType moduleType : moduleDevicePointsMap.keySet()) {
                        Map<DeviceType, List<MeasurementPoint>> devicePointsMap = moduleDevicePointsMap.get(moduleType);
                        if (devicePointsMap == null) {
                                continue;
                        }

                        // 遍历所有设备类型
                        for (DeviceType deviceType : devicePointsMap.keySet()) {
                                List<MeasurementPoint> points = devicePointsMap.get(deviceType);
                                if (points == null) {
                                        continue;
                                }

                                // 遍历所有测点，设置更新频率
                                for (MeasurementPoint point : points) {
                                        // 根据测点类型设置不同的更新频率
                                        if (moduleType == ModuleType.GAS_MONITORING) {
                                                // 气体检测需要较高频率
                                                point.setUpdateFrequency(6000); // 6秒
                                        } else if (moduleType == ModuleType.GRAIN_SITUATION) {
                                                // 粮情检测所有测点统一设置为10秒
                                                point.setUpdateFrequency(10000); // 10秒
                                        } else if (moduleType == ModuleType.VENTILATION) {
                                                // 通风设备状态需要较快响应
                                                if (point.getPointType() == MeasurementPoint.PointType.STATUS) {
                                                        point.setUpdateFrequency(2000); // 状态2秒
                                                } else if (point.getPointType() == MeasurementPoint.PointType.FAULT_ALARM) {
                                                        point.setUpdateFrequency(3000); // 报警1秒
                                                } else {
                                                        point.setUpdateFrequency(5000); // 其他5秒
                                                }
                                        } else if (moduleType == ModuleType.POWER_MONITORING) {
                                                // 电力监测变化较慢
                                                point.setUpdateFrequency(30000); // 30秒
                                        } else {
                                                // 默认更新频率
                                                point.setUpdateFrequency(5000); // 5秒
                                        }

                                        // 属性测点也需要设置更新频率
                                        for (MeasurementPoint attributePoint : point.getAttributePoints()) {
                                                if (attributePoint
                                                                .getPointType() == MeasurementPoint.PointType.FAULT_ALARM) {
                                                        attributePoint.setUpdateFrequency(3000); // 故障报警1秒
                                                } else if (attributePoint
                                                                .getPointType() == MeasurementPoint.PointType.RUN_STATUS) {
                                                        attributePoint.setUpdateFrequency(3000); // 运行状态2秒
                                                } else {
                                                        attributePoint.setUpdateFrequency(5000); // 其他5秒
                                                }
                                        }
                                }
                        }
                }
        }

        /**
         * 初始化测点映射
         */
        private static void initPointMaps() {
                // 遍历所有模块
                for (ModuleType moduleType : PlcMeasurementUtils.getAllModuleTypes()) {
                        Map<DeviceType, List<MeasurementPoint>> devicePointsMap = moduleDevicePointsMap.get(moduleType);
                        if (devicePointsMap == null) {
                                continue;
                        }

                        // 遍历所有设备类型
                        for (DeviceType deviceType : devicePointsMap.keySet()) {
                                List<MeasurementPoint> points = devicePointsMap.get(deviceType);
                                if (points == null) {
                                        continue;
                                }

                                // 遍历所有测点，建立映射
                                for (MeasurementPoint point : points) {
                                        // 建立英文名称到测点的映射（英文名称唯一）
                                        englishNamePointMap.put(point.getEnglishName(), point);
                                }
                        }
                }
        }

        /**
         * 友人PLC
         */
        public static void initYouRenPointList() {

                // 创建电力检测测点列表
                List<MeasurementPoint> powerMonitoringPoints = new ArrayList<>();

                // 添加电力测点
                powerMonitoringPoints.add(new MeasurementPoint("有功电能", "Active_Energy", "40001", "KWH",
                                "总有功电能", 0, 999999, 0, 0, 1.0f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("A相电压", "Phase_A_Voltage", "40098", "V",
                                "A相电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("B相电压", "Phase_B_Voltage", "40099", "V",
                                "B相电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("C相电压", "Phase_C_Voltage", "40100", "V",
                                "C相电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("总功率因数", "Total_Power_Factor", "40119", "",
                                "总功率因数", 0, 1, 0, 0, 1000f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("频率", "Frequency", "40120", "Hz",
                                "电网频率", 0, 100, 0, 0, 100f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("A-B线电压", "Line_Voltage_AB", "40121", "V",
                                "A-B线电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("C-B线电压", "Line_Voltage_CB", "40122", "V",
                                "C-B线电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                powerMonitoringPoints.add(new MeasurementPoint("A-C线电压", "Line_Voltage_AC", "40123", "V",
                                "A-C线电压", 0, 500, 0, 0, 10f, MeasurementPoint.PointType.VALUE));

                // 创建电力监控模块映射
                Map<DeviceType, List<MeasurementPoint>> powerMonitoringMap = new HashMap<>();
                powerMonitoringMap.put(DeviceType.OMRON_CP, powerMonitoringPoints);

                // 将电力监控模块添加到总映射中
                moduleDevicePointsMap.put(ModuleType.POWER_MONITORING, powerMonitoringMap);

                // 粮情检测模块
                List<MeasurementPoint> grainSituationPoints = new ArrayList<>();

                // 添加温度测点 - 电缆1
                grainSituationPoints.add(new MeasurementPoint("电缆1测点1温度", "Cable1_Temp1", "40001", "℃",
                                "电缆1测点1温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点2温度", "Cable1_Temp2", "40002", "℃",
                                "电缆1测点2温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点3温度", "Cable1_Temp3", "40003", "℃",
                                "电缆1测点3温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点4温度", "Cable1_Temp4", "40004", "℃",
                                "电缆1测点4温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));

                // 添加温度测点 - 电缆2
                grainSituationPoints.add(new MeasurementPoint("电缆2测点1温度", "Cable2_Temp1", "40005", "℃",
                                "电缆2测点1温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点2温度", "Cable2_Temp2", "40006", "℃",
                                "电缆2测点2温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点3温度", "Cable2_Temp3", "40007", "℃",
                                "电缆2测点3温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点4温度", "Cable2_Temp4", "40008", "℃",
                                "电缆2测点4温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));

                // 添加温度测点 - 电缆3
                grainSituationPoints.add(new MeasurementPoint("电缆3测点1温度", "Cable3_Temp1", "40009", "℃",
                                "电缆3测点1温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点2温度", "Cable3_Temp2", "40010", "℃",
                                "电缆3测点2温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点3温度", "Cable3_Temp3", "40011", "℃",
                                "电缆3测点3温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点4温度", "Cable3_Temp4", "40012", "℃",
                                "电缆3测点4温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));

                // 添加温度测点 - 电缆4
                grainSituationPoints.add(new MeasurementPoint("电缆4测点1温度", "Cable4_Temp1", "40013", "℃",
                                "电缆4测点1温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点2温度", "Cable4_Temp2", "40014", "℃",
                                "电缆4测点2温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点3温度", "Cable4_Temp3", "40015", "℃",
                                "电缆4测点3温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点4温度", "Cable4_Temp4", "40016", "℃",
                                "电缆4测点4温度", 0, 100, 35, 45, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.TEMPERATURE_SENSOR, 0.0));

                // 添加湿度测点 - 电缆1
                grainSituationPoints.add(new MeasurementPoint("电缆1测点1湿度", "Cable1_Humidity1", "42049", "%",
                                "电缆1测点1湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点2湿度", "Cable1_Humidity2", "42050", "%",
                                "电缆1测点2湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点3湿度", "Cable1_Humidity3", "42051", "%",
                                "电缆1测点3湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆1测点4湿度", "Cable1_Humidity4", "42052", "%",
                                "电缆1测点4湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));

                // 添加湿度测点 - 电缆2
                grainSituationPoints.add(new MeasurementPoint("电缆2测点1湿度", "Cable2_Humidity1", "42053", "%",
                                "电缆2测点1湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点2湿度", "Cable2_Humidity2", "42054", "%",
                                "电缆2测点2湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点3湿度", "Cable2_Humidity3", "42055", "%",
                                "电缆2测点3湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆2测点4湿度", "Cable2_Humidity4", "42056", "%",
                                "电缆2测点4湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));

                // 添加湿度测点 - 电缆3
                grainSituationPoints.add(new MeasurementPoint("电缆3测点1湿度", "Cable3_Humidity1", "42057", "%",
                                "电缆3测点1湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点2湿度", "Cable3_Humidity2", "42058", "%",
                                "电缆3测点2湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点3湿度", "Cable3_Humidity3", "42059", "%",
                                "电缆3测点3湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆3测点4湿度", "Cable3_Humidity4", "42060", "%",
                                "电缆3测点4湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));

                // 添加湿度测点 - 电缆4
                grainSituationPoints.add(new MeasurementPoint("电缆4测点1湿度", "Cable4_Humidity1", "42061", "%",
                                "电缆4测点1湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点2湿度", "Cable4_Humidity2", "42062", "%",
                                "电缆4测点2湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点3湿度", "Cable4_Humidity3", "42063", "%",
                                "电缆4测点3湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));
                grainSituationPoints.add(new MeasurementPoint("电缆4测点4湿度", "Cable4_Humidity4", "42064", "%",
                                "电缆4测点4湿度", 0, 100, 70, 85, 10.0f, MeasurementPoint.PointType.VALUE,
                                MeasurementPoint.DeviceSubType.HUMIDITY_SENSOR, 0.0));

                // 将粮情测点添加到映射中
                Map<DeviceType, List<MeasurementPoint>> grainSituationMap = new HashMap<>();
                grainSituationMap.put(DeviceType.GRAIN_SITUATION_FAN, grainSituationPoints);
                moduleDevicePointsMap.put(ModuleType.GRAIN_SITUATION, grainSituationMap);

        }

}